package cn.lokei.gateway.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;


@SpringBootConfiguration
@PropertySource(value = { "classpath:redis/redis.properties" })
public class RedisConfiguration {
  @Value("${redis.node.maxTotal}")
  private Integer maxTotal;

  @Value("${redis.node.host}")
  private String host;

  @Value("${redis.node.port}")
  private Integer port;

  public JedisPoolConfig jedisPoolConfig() {
    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    jedisPoolConfig.setMaxTotal(maxTotal);
    return jedisPoolConfig;
  }

  @Bean
  public JedisPool jedisPool() {
    JedisPoolConfig jedisPoolConfig = jedisPoolConfig();
    return new JedisPool(jedisPoolConfig, host, port);
  }
}
